import {isEmpty, resetState,isNotEmptyAndFunc} from '@/utils/index';

const initState = {
    network:{
        isConnected:true,
        networkType:undefined,
        //permitPlayVideoInWifi: false,
        //init:false
    },
    version:{
        code:'1.0.0',
        name:'森林公安',
        about:'',
        init:false
    },
    statusbar:{
        height:0
    },
    systemInfo:{
        windowWidth:0,
        windowHeight:0,
        brand:'',
        model:''
    }
};
const settings = {
    namespaced: true,
    state: {
        ...initState,
        initState: () => initState
    },
    mutations: {
        resetState(state, payload) {
            resetState(state);
        },
        updateSystemInfo(state,payload){
            const {statusBarHeight,windowWidth,windowHeight,brand,model} = payload;
            if(!isEmpty(windowWidth)){
                state.systemInfo.windowWidth = windowWidth;
            }
            if(!isEmpty(windowHeight)){
                state.systemInfo.windowHeight = windowHeight;
            }
            if(!isEmpty(statusBarHeight)){
                state.statusbar.height = statusBarHeight;
            }
            if(!isEmpty(brand)){
                state.systemInfo.brand = brand;
            }
            if(!isEmpty(model)){
                state.systemInfo.model = model;
            }
        },
        updateNetWork(state,payload){
            console.log('updateNetWork:')
            const {networkType,permitPlayVideoInWifi,isConnected} = payload;
            console.log('updateNetWork:payload:',payload)
            if (networkType!=undefined){
                state.network.networkType = networkType;
                state.network.isConnected = isConnected;
            }
        },
        updateVersionCode(state,payload)
        {
            const {code,name} = payload;
            state.version.code = code;
            state.version.name = name;
        }
    },
    actions: {
        updateSystemInfo({commit, state}, payload){
            commit('updateSystemInfo',payload);
        },
        async resetState({commit, state}, payload) {
            commit('resetState')
        },
        async updateNetWork({commit, state}, payload){
            commit('updateNetWork',payload);
        },
        async updateVersionCode({commit,state},payload){
            commit('updateVersionCode',payload);
        }
    },
    getters: {
        // getNetWork:state=>{
        //     let {network} = state;
        //         if(!network.init){
			// 		const network = uni.getStorageSync('network');
			// 		console.log('network:',network)
        //             const {permitPlayVideoInWifi} = network;
        //             console.log('permitPlayVideoInWifi:',permitPlayVideoInWifi)
        //             if(permitPlayVideoInWifi){
        //                 network.permitPlayVideoInWifi =  permitPlayVideoInWifi;
        //                 network.init = true;
        //             }
        //         }
        //     return network;
        // },
        getVersion:state=>{
            let {version} = state;
            return version;
        }
        // ifdef APP-PLUS
        // getCache:state=>{
        //     let {cache} = state;
        //     if(!cache.init){
        //         const {currentSize} = uni.getStorageInfoSync();
        //         cache.volume =  currentSize
        //     }
        //     return cache;
        // }
        // endif
    },
    modules: {}
};
export default settings;